home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / toeplitz < prev    next >
Text File  |  1994-06-13  |  1KB  |  53 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. // Synopsis:    Toeplitz matrix.
  4.  
  5. // Syntax:    toeplitz ( C )
  6. //        toeplitz ( C , R )
  7.  
  8. //  Description:
  9.  
  10. //      The toeplitz function returns a non-symmetric Toeplitz matrix
  11. //      having C as its first column and R as its first
  12. //      row. `toeplitz(C)' is a symmetric (or Hermitian) Toeplitz 
  13. //      matrix. 
  14.  
  15. //      If the 1st element of C and R do not agree, then C[1] "wins".
  16.  
  17. //  See also hankel.r
  18. //-------------------------------------------------------------------//
  19.  
  20. toeplitz = function ( c , r ) 
  21. {
  22.   local(c, r, nc, nr, t, i);
  23.  
  24.   if (class(c) != "num") 
  25.   {
  26.     error ("toeplitz: Inputs must be numeric");
  27.   }
  28.  
  29.   c = c[:];                 // Force column-vector.
  30.   nr = length (c);          // No. of rows in t.
  31.  
  32.   if (!exist (r)) 
  33.   {
  34.     r = c';                 // Symmetric / Hermitian
  35.   else
  36.     if (class(r) != "num") 
  37.     { 
  38.       error ("toeplitz: Inputs must be numeric"); 
  39.     }
  40.   }
  41.   
  42.   r = r[:].';               // Force row-vector.
  43.   nc = length (r);          // No. of columns in t.
  44.   t = zeros (nr, nc);
  45.  
  46.   for (i in 1:min(nr,nc))
  47.   {
  48.     t[i;i:t.nc] = r[1:r.n-i+1];  // Fill upper triangle rows.
  49.     t[i:t.nr;i] = c[1:c.n-i+1];  // Fill lower triangle columns.
  50.   }
  51.   return t;
  52. };
  53.